package com.syt.user.api;


import com.syt.model.user.Patient;
import com.syt.result.Result;
import com.syt.user.service.PatientService;
import com.syt.utils.AuthContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 就诊人表 前端控制器
 * </p>
 *
 * @author xx
 * @since 2023-02-20
 */
@Api(tags = "就诊管理接口")
@RestController
@RequestMapping("/api/user/patient")
public class PatientApiController {

    @Autowired
    private PatientService patientService;

    @ApiOperation(value = "获取就诊人")
    @GetMapping("/inner/get/{id}")
    public Patient getPatientOrder(@PathVariable Long id){
        Patient patient = patientService.getPatientById(id);
        return patient;
    }


    @ApiOperation(value = "获取就诊人列表")
    @GetMapping("/auth/findPatientAllByUserId")
    public Result getPatientAllByUserId(HttpServletRequest request){
       //获取当前登录用户id
        Long userId = AuthContextHolder.getUserId(request);
        List<Patient> patientList= patientService.findPatientAllByUserId(userId);
        return Result.ok(patientList);
    }

    //添加就诊人
    @ApiOperation(value = "添加就诊人")
    @PostMapping("/auth/savePatient")
    public Result savePatient(@RequestBody Patient patient, HttpServletRequest request){
        //获取登录用户id
        Long userId = AuthContextHolder.getUserId(request);
        patient.setUserId(userId);
        patientService.addPatient(patient);
        return Result.ok();
    }


    //根据id获取就诊人信息
    @ApiOperation(value = "根据id获取就诊人信息")
    @GetMapping("/auth/get/{id}")
    public Result getPatientById(@PathVariable Long id){
        Patient patient= patientService.getPatientById(id);
        return Result.ok(patient);
    }

    //修改就诊人
    @ApiOperation(value = "修改就诊人")
    @PostMapping("/auth/update")
    public Result updatePatient(@RequestBody Patient patient){
        patientService.updatePatient(patient);
        return Result.ok();
    }

    //删除就诊人
    @ApiOperation(value = "删除就诊人")
    @DeleteMapping("/auth/remove/{id}")
    public Result removePatientById(@PathVariable Long id){
        patientService.removePatientById(id);
        return Result.ok();
    }


}
